package com.nuanshui.heatedloan.baseservice.service;

import com.nuanshui.framework.res.ResourceFacade;
import com.nuanshui.framework.springContext.SpringPropertiesUtil;
import com.nuanshui.heatedloan.baseservice.facade.ImageService;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.dubbo.extension.DubboContextManager;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public  class ResourceFacadePostProcessor implements BeanPostProcessor,DisposableBean, InitializingBean {

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
        if(bean instanceof ResourceFacade) {
			ResourceFacadeNonProdImpl resourceFacadeObj=(ResourceFacadeNonProdImpl)bean;
			ImageService imageService= DubboContextManager.getBean(ImageService.class,true, GlobalParam.BASESERVICE_DUBBO_SERVER_VERSION);
			if(imageService!=null) {
				resourceFacadeObj.setImageService(imageService);
			}
		}
		return bean;
	}


	@Override
	public void afterPropertiesSet() throws Exception {

		
	}

	@Override
	public void destroy() throws Exception {
		
		
	}


}
